<!-- 搜索项目 -->
<template>
  <h-select-input-popup
    ref="hSelectInputPopup"
    v-model="val"
    v-bind="$attrs"
    v-on="$listeners"
    :params="queryParams"
    :keywords.sync="keywords"
    :getList="getList"
    @getDetail="getDetail"
		searchPlaceholder="请输入项目名称"
    @change="$emit('change', $event)"
  >
    <template v-slot:default="{ item }">
			<view class="project-item">
				<view class="option">
					<view class="lf">档案编号</view>
					<view class="rl">{{ item.finalNo }}</view>
				</view>
				<view class="option">
					<view class="lf">项目名称</view>
					<view class="rl">{{ item.projectName }}</view>
				</view>
				<view class="option">
					<view class="lf">项目承接人</view>
					<view class="rl">{{ item.undertaker_dictText }}</view>
				</view>
				<view class="option">
					<view class="lf">业绩归属年度</view>
					<view class="rl">{{ item.year_dictText }}</view>
				</view>
				<view class="option">
					<view class="lf">经营团队</view>
					<view class="rl">{{ item.businessTeam_dictText }}</view>
				</view>
				<view class="option">
					<view class="lf">业主单位</view>
					<view class="rl">{{ item.ownerUnit_dictText }}</view>
				</view>
				
			</view>
    </template>
  </h-select-input-popup>
</template>

<script>
import { erpOmcProjectTaskList, erpOmcTenderFinalId, erpOmcTenderFinalIds } from '@/api/index.js'

export default {
  name: 'HSelectOilCardInputPopup',
  data() {
    return {
      getList: erpOmcProjectTaskList,
      params: {
        column: 'createTime',
        order: 'desc',
        pageNo: 1,
        pageSize: 10,
        projectName: '',
      },
      keywords: '',
    }
  },
  model: {
    prop: 'value',
    event: 'input',
  },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
	tenderUnit: {
		type: String,
		default: ''
	},
	isResult: {
		type: Boolean,
		default: false
	},
	isBid: {
		type: Number,
		default: 0
	}
  },
  watch: {
    keywords: {
      handler(val) {
        if (val) {
          this.params.projectName = '*' + val + '*'
        } else {
          this.params.projectName = ''
        }
      },
      immediate: true,
    },
  },
  computed: {
    val: {
      get() {
        return this.value
      },
      set() {
        this.$emit('input', this.value)
      }
    },
		queryParams() {
			const params = {
				...this.params
			}
			if (this.keywords) {
				params.projectName = '*' + this.keywords + '*'
			}
			if (this.tenderUnit) {
				params.tenderUnit = this.tenderUnit
			}
			if (this.isResult) {
				params.isResult = this.isResult
			}
			if (this.isBid !== null || this.isBid !== undefined || this.isBid !== '') {
				params.isBid = this.isBid
			}
			return params
		}
  },
  methods: {
    // 获取详情
    getDetail(value) {
      erpOmcTenderFinalId({ id: value }).then((res) => {
        if (res.success) {
          this.$refs.hSelectInputPopup.title = res.result.projectName
          this.$emit('select', {
            data: res.result,
            id: value
          })
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>

// 按钮
.btn {
  position: fixed;
  bottom: 20rpx;
  width: 95%;
}
</style>
